package com.liury.bbs.service;

import com.liury.bbs.entity.Kind;
import com.liury.bbs.entity.Title;
import com.liury.bbs.mapper.KindMapper;
import com.liury.bbs.mapper.ReplyMapper;
import com.liury.bbs.mapper.TitleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexService {
    //查询kind下的主题数和回帖数
    @Autowired
    KindMapper kindMapper;
    @Autowired
    TitleMapper titleMapper;
    @Autowired
    ReplyMapper replyMapper;
    public List<Kind> findAll(){
        List<Kind> list=kindMapper.find();
        for(Kind k:list){
            int t=titleMapper.counttitlebykind(k.getId());
            k.setCounttitle(t);
            int r=replyMapper.countreplybykind(k.getId());
            k.setCountreply(r);
            Title title=titleMapper.newTitle(k.getId());
            k.setNewTitle(title);
        }
        return list;
    }
}
